{
 "cells": [
  {
   "cell_type": "markdown",
   "source": "# Spatial cross-section models: Application to crime data",
   "metadata": {
    "cell_id": "00000-636bbdb9-d223-4a37-880a-fa822dc391e2",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "markdown",
   "source": "[![DOI](https://zenodo.org/badge/387109687.svg)](https://zenodo.org/badge/latestdoi/387109687)",
   "metadata": {
    "cell_id": "00001-82252ed7-e3fc-444b-a26d-827a846326eb",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "markdown",
   "source": "> Mendez C. (2021). Spatial econometrics for cross-sectional data: Columbus crime example. DOI: [10.5281/zenodo.5151076](https://doi.org/10.5281/zenodo.5151076). Notebook available at  https://deepnote.com/@carlos-mendez/STATA-Spatial-cross-section-00WMK3sKQl-z6oVRkTQgCQ \n",
   "metadata": {
    "cell_id": "00002-d9eb09ea-5243-455e-b8da-cb2c37b64753",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "markdown",
   "source": "## Roadmap",
   "metadata": {
    "cell_id": "00003-a65417c6-2454-436b-9439-fccb0cce714f",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "markdown",
   "source": "![](https://github.com/quarcs-lab/data-open/raw/master/Columbus/columbus/SpatialEcometricsRoad.jpg)",
   "metadata": {
    "cell_id": "00004-efac0974-30c9-4263-b731-1abf0e156a68",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00005-a70de091-8aa6-4fd0-b2f6-a72e2001e7f2",
    "deepnote_cell_type": "code"
   },
   "source": "* Clean your environment\nclear all\nmacro drop _all\nset more off\n*cls\n*version 17",
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00006-86d2c92b-31dc-4dee-af44-3ebe66a6b29e",
    "deepnote_cell_type": "code"
   },
   "source": "* Install packages: esttab, estadd, eststo, estout, estpost (http://repec.sowi.unibe.ch/stata/estout/index.html)\n* net install st0085_2, from(http://www.stata-journal.com/software/sj14-2)\n* ssc install estout, replace",
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": "## Import W and data",
   "metadata": {
    "cell_id": "00007-6b04f3fe-3ba9-4b2b-b485-8e5a7d05af62",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00008-84922820-a445-4c91-831b-aa5384637f45",
    "deepnote_cell_type": "code"
   },
   "source": "* Import .dta weights matrix with spmatrix (official function from Stata15)\nuse \"https://github.com/quarcs-lab/data-open/raw/master/Columbus/columbus/Wqueen_fromStata_spmat.dta\", clear\ngen id = _n\norder id, first\nspset id\nspmatrix fromdata WqueenS_fromStata15 = v*, normalize(row) replace\nspmatrix summarize WqueenS_fromStata15",
   "execution_count": null,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "\n\n\n\n\n      Sp dataset: Wqueen_fromStata_spmat.dta\nLinked shapefile: <none>\n            Data: Cross sectional\n Spatial-unit ID: _ID (equal to id)\n     Coordinates: <none>\n\n\n\nWeighting matrix WqueenS_fromStata15\n---------------------------------------\n           Type |           contiguity\n  Normalization |                  row\n      Dimension |              49 x 49\nElements        |\n   minimum      |                    0\n   minimum > 0  |                   .1\n   mean         |             .0204082\n   max          |                   .5\nNeighbors       |\n   minimum      |                    2\n   mean         |             4.816327\n   maximum      |                   10\n---------------------------------------\n"
    }
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00009-26c9a95f-4714-468e-a5ab-d20163648350",
    "deepnote_cell_type": "code"
   },
   "source": "* Import the dataset and set up the spatial id: https://geodacenter.github.io/data-and-lab/columbus/\nuse \"https://github.com/quarcs-lab/data-open/raw/master/Columbus/columbus/columbusDbase.dta\", clear\nspset id",
   "execution_count": null,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "\n\n\n      Sp dataset: columbusDbase.dta\nLinked shapefile: <none>\n            Data: Cross sectional\n Spatial-unit ID: _ID (equal to id)\n     Coordinates: <none>\n"
    }
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00010-75d3f61d-f8fd-4ed2-bd70-e38918836f99",
    "deepnote_cell_type": "code"
   },
   "source": "label var CRIME \"Crime\"\nlabel var INC   \"Income\"\nlabel var HOVAL \"House value\"",
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": "## OLS",
   "metadata": {
    "cell_id": "00011-db85a300-0b6c-48fb-9d2c-c6b4f53b603b",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00012-13c9aca6-7321-4a60-9a96-6fec78ecf397",
    "deepnote_cell_type": "code"
   },
   "source": "regress CRIME INC HOVAL\neststo OLS\n\nestat ic\nmat s=r(S)\nquietly estadd scalar AIC = s[1,5]",
   "execution_count": null,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "\n\n      Source |       SS           df       MS      Number of obs   =        49\n-------------+----------------------------------   F(2, 46)        =     28.39\n       Model |  7423.32674         2  3711.66337   Prob > F        =    0.0000\n    Residual |  6014.89274        46  130.758538   R-squared       =    0.5524\n-------------+----------------------------------   Adj R-squared   =    0.5329\n       Total |  13438.2195        48  279.962906   Root MSE        =    11.435\n\n------------------------------------------------------------------------------\n       CRIME | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]\n-------------+----------------------------------------------------------------\n         INC |  -1.597311   .3341308    -4.78   0.000    -2.269881   -.9247405\n       HOVAL |  -.2739315   .1031987    -2.65   0.011    -.4816597   -.0662033\n       _cons |   68.61896   4.735486    14.49   0.000     59.08692      78.151\n------------------------------------------------------------------------------\n\n\n\nAkaike's information criterion and Bayesian information criterion\n\n-----------------------------------------------------------------------------\n       Model |          N   ll(null)  ll(model)      df        AIC        BIC\n-------------+---------------------------------------------------------------\n         OLS |         49  -207.0719  -187.3772       3   380.7545   386.4299\n-----------------------------------------------------------------------------\nNote: BIC uses N = number of observations. See [R] BIC note.\n\n\n"
    }
   ]
  },
  {
   "cell_type": "markdown",
   "source": "### Moran's I test",
   "metadata": {
    "cell_id": "00013-6c2f2393-937b-4de5-bf15-cb39a1ce3e73",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00014-5c38e33e-2078-493f-929c-931d0ddfc7d0",
    "deepnote_cell_type": "code"
   },
   "source": "regress CRIME INC HOVAL\nestat moran, errorlag(WqueenS_fromStata15)",
   "execution_count": null,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "\n\n      Source |       SS           df       MS      Number of obs   =        49\n-------------+----------------------------------   F(2, 46)        =     28.39\n       Model |  7423.32674         2  3711.66337   Prob > F        =    0.0000\n    Residual |  6014.89274        46  130.758538   R-squared       =    0.5524\n-------------+----------------------------------   Adj R-squared   =    0.5329\n       Total |  13438.2195        48  279.962906   Root MSE        =    11.435\n\n------------------------------------------------------------------------------\n       CRIME | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]\n-------------+----------------------------------------------------------------\n         INC |  -1.597311   .3341308    -4.78   0.000    -2.269881   -.9247405\n       HOVAL |  -.2739315   .1031987    -2.65   0.011    -.4816597   -.0662033\n       _cons |   68.61896   4.735486    14.49   0.000     59.08692      78.151\n------------------------------------------------------------------------------\n\n\nMoran test for spatial dependence\n         H0: Error terms are i.i.d.\n         Errorlags:  WqueenS_fromStata15\n\n         chi2(1)      =     5.21\n         Prob > chi2  =   0.0225\n"
    }
   ]
  },
  {
   "cell_type": "markdown",
   "source": "### LM tests",
   "metadata": {
    "tags": [],
    "cell_id": "00015-0e70ea55-ae4e-4365-9b16-cb8f370121de",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00016-8e5cf05a-7d54-459d-a6e0-864651e8b4b6",
    "deepnote_cell_type": "code"
   },
   "source": "spatwmat using \"https://github.com/quarcs-lab/data-open/raw/master/Columbus/columbus/Wqueen_fromStata_spmat.dta\", name(WqueenS_fromStata_spatwmat) eigenval(eWqueenS_fromStata_spatwmat) standardize",
   "execution_count": null,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "\n\nThe following matrices have been created:\n\n1. Imported binary weights matrix WqueenS_fromStata_spatwmat (row-standardized)\n   Dimension: 49x49\n\n2. Eigenvalues matrix eWqueenS_fromStata_spatwmat\n   Dimension: 49x1\n\n\n"
    }
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00017-e361f75c-3c7e-469e-85d5-0b3f83a92784",
    "deepnote_cell_type": "code"
   },
   "source": "quietly reg CRIME INC HOVAL\nspatdiag, weights(WqueenS_fromStata_spatwmat)",
   "execution_count": null,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "\n\n\n\nDiagnostic tests for spatial dependence in OLS regression\n---------------------------------------------------------\n\n\nFitted model\n------------------------------------------------------------\nCRIME = INC + HOVAL\n------------------------------------------------------------\n\nWeights matrix\n------------------------------------------------------------\nName: WqueenS_fromStata_spatwmat\nType: Imported (binary)\nRow-standardized: Yes\n------------------------------------------------------------\n\nDiagnostics\n------------------------------------------------------------\nTest                           |  Statistic    df   p-value\n-------------------------------+----------------------------\nSpatial error:                 |\n  Moran's I                    |     2.840      1    0.005\n  Lagrange multiplier          |     5.206      1    0.023\n  Robust Lagrange multiplier   |     0.044      1    0.834\n                               |\nSpatial lag:                   |\n  Lagrange multiplier          |     8.898      1    0.003\n  Robust Lagrange multiplier   |     3.736      1    0.053\n------------------------------------------------------------\n\n\n"
    }
   ]
  },
  {
   "cell_type": "markdown",
   "source": "## SAR",
   "metadata": {
    "cell_id": "00018-a498b9ed-c662-4ff5-8060-ca1b378835e8",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00019-73a8b2bf-abd4-422d-81ff-00feb90c2dd6",
    "deepnote_cell_type": "code"
   },
   "source": "spregress CRIME INC HOVAL, ml dvarlag(WqueenS_fromStata15)\neststo SAR\n\nestat ic\nmat s=r(S)\nquietly estadd scalar AIC = s[1,5]\n\nestat impact",
   "execution_count": null,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "\n  (49 observations)\n  (49 observations (places) used)\n  (weighting matrix defines 49 places)\n\nPerforming grid search ... finished \n\nOptimizing concentrated log likelihood:\n\nIteration 0:   log likelihood = -182.69106  \nIteration 1:   log likelihood = -182.67397  \nIteration 2:   log likelihood = -182.67397  \n\nOptimizing unconcentrated log likelihood:\n\nIteration 0:   log likelihood = -182.67397  \nIteration 1:   log likelihood = -182.67397  (backed up)\n\nSpatial autoregressive model                            Number of obs =     49\nMaximum likelihood estimates                            Wald chi2(3)  =  88.00\n                                                        Prob > chi2   = 0.0000\nLog likelihood = -182.67397                             Pseudo R2     = 0.5806\n\n-------------------------------------------------------------------------------\n        CRIME | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]\n--------------+----------------------------------------------------------------\nCRIME         |\n          INC |  -1.048728   .3304297    -3.17   0.002    -1.696359   -.4010978\n        HOVAL |  -.2663348   .0888474    -3.00   0.003    -.4404725   -.0921971\n        _cons |   45.60325   7.951826     5.73   0.000     30.01796    61.18854\n--------------+----------------------------------------------------------------\nWqueenS_fr~15 |\n        CRIME |   .4233254   .1255855     3.37   0.001     .1771824    .6694684\n--------------+----------------------------------------------------------------\n  var(e.CRIME)|   96.85718   19.77581                      64.91392    144.5193\n-------------------------------------------------------------------------------\nWald test of spatial terms:          chi2(1) = 11.36      Prob > chi2 = 0.0007\n\n\n\nAkaike's information criterion and Bayesian information criterion\n\n-----------------------------------------------------------------------------\n       Model |          N   ll(null)  ll(model)      df        AIC        BIC\n-------------+---------------------------------------------------------------\n         SAR |         49          .   -182.674       5   375.3479    384.807\n-----------------------------------------------------------------------------\nNote: BIC uses N = number of observations. See [R] BIC note.\n\n\n\n\nprogress   : 50% 100% \n\nAverage impacts                                 Number of obs     =         49\n\n------------------------------------------------------------------------------\n             |            Delta-Method\n             |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]\n-------------+----------------------------------------------------------------\ndirect       |\n         INC |  -1.100895   .3302446    -3.33   0.001    -1.748163   -.4536279\n       HOVAL |  -.2795832   .0935004    -2.99   0.003    -.4628406   -.0963258\n-------------+----------------------------------------------------------------\nindirect     |\n         INC |  -.7176833   .3163904    -2.27   0.023    -1.337797   -.0975695\n       HOVAL |  -.1822627   .1083184    -1.68   0.092    -.3945629    .0300375\n-------------+----------------------------------------------------------------\ntotal        |\n         INC |  -1.818579   .5115003    -3.56   0.000    -2.821101   -.8160566\n       HOVAL |  -.4618459   .1818435    -2.54   0.011    -.8182526   -.1054393\n------------------------------------------------------------------------------\n"
    }
   ]
  },
  {
   "cell_type": "markdown",
   "source": "## SEM",
   "metadata": {
    "cell_id": "00020-10221ce2-f191-46f7-a5c1-d6117cb83aa0",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00021-7db098fd-3374-49ce-98fa-d70c89e39f74",
    "deepnote_cell_type": "code"
   },
   "source": "spregress CRIME INC HOVAL, ml errorlag(WqueenS_fromStata15)\neststo SEM\n\nestat ic\nmat s=r(S)\nquietly estadd scalar AIC = s[1,5]\n\nestat impact",
   "execution_count": null,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "\n  (49 observations)\n  (49 observations (places) used)\n  (weighting matrix defines 49 places)\n\nPerforming grid search ... finished \n\nOptimizing concentrated log likelihood:\n\nIteration 0:   log likelihood = -183.79112  \nIteration 1:   log likelihood =  -183.7495  \nIteration 2:   log likelihood = -183.74943  \nIteration 3:   log likelihood = -183.74943  \n\nOptimizing unconcentrated log likelihood:\n\nIteration 0:   log likelihood = -183.74943  \nIteration 1:   log likelihood = -183.74943  (backed up)\n\nSpatial autoregressive model                            Number of obs =     49\nMaximum likelihood estimates                            Wald chi2(2)  =  30.15\n                                                        Prob > chi2   = 0.0000\nLog likelihood = -183.74943                             Pseudo R2     = 0.5362\n\n-------------------------------------------------------------------------------\n        CRIME | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]\n--------------+----------------------------------------------------------------\nCRIME         |\n          INC |  -.9573054   .3771546    -2.54   0.011    -1.696515   -.2180961\n        HOVAL |  -.3045593   .0921607    -3.30   0.001    -.4851909   -.1239276\n        _cons |   60.27947   5.904297    10.21   0.000     48.70726    71.85168\n--------------+----------------------------------------------------------------\nWqueenS_fr~15 |\n      e.CRIME |   .5467529   .1575357     3.47   0.001     .2379886    .8555173\n--------------+----------------------------------------------------------------\n  var(e.CRIME)|   97.67424   20.43916                      64.81252    147.1977\n-------------------------------------------------------------------------------\nWald test of spatial terms:          chi2(1) = 12.05      Prob > chi2 = 0.0005\n\n\n\nAkaike's information criterion and Bayesian information criterion\n\n-----------------------------------------------------------------------------\n       Model |          N   ll(null)  ll(model)      df        AIC        BIC\n-------------+---------------------------------------------------------------\n         SEM |         49          .  -183.7494       5   377.4989    386.958\n-----------------------------------------------------------------------------\nNote: BIC uses N = number of observations. See [R] BIC note.\n\n\n\n\nprogress   : 50% 100% \n\nAverage impacts                                 Number of obs     =         49\n\n------------------------------------------------------------------------------\n             |            Delta-Method\n             |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]\n-------------+----------------------------------------------------------------\ndirect       |\n         INC |  -.9573054   .3771546    -2.54   0.011    -1.696515   -.2180961\n       HOVAL |  -.3045593   .0921607    -3.30   0.001    -.4851909   -.1239276\n-------------+----------------------------------------------------------------\nindirect     |\n         INC |          0  (omitted)\n       HOVAL |          0  (omitted)\n-------------+----------------------------------------------------------------\ntotal        |\n         INC |  -.9573054   .3771546    -2.54   0.011    -1.696515   -.2180961\n       HOVAL |  -.3045593   .0921607    -3.30   0.001    -.4851909   -.1239276\n------------------------------------------------------------------------------\n"
    }
   ]
  },
  {
   "cell_type": "markdown",
   "source": "## SLX",
   "metadata": {
    "cell_id": "00022-67d06de0-a71d-4597-b53b-6509e710007a",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00023-65fa5b25-fade-4a66-bd12-7a8802c48aee",
    "deepnote_cell_type": "code"
   },
   "source": "spregress CRIME INC HOVAL, ml ivarlag(WqueenS_fromStata15: INC HOVAL)\neststo SLX\n\nestat ic\nmat s=r(S)\nquietly estadd scalar AIC = s[1,5]\n\nestat impact",
   "execution_count": null,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "\n  (49 observations)\n  (49 observations (places) used)\n  (weighting matrix defines 49 places)\n\nOptimizing unconcentrated log likelihood:\n\nIteration 0:   log likelihood =  -183.9706  \nIteration 1:   log likelihood =  -183.9706  \n\nSpatial autoregressive model                            Number of obs =     49\nMaximum likelihood estimates                            Wald chi2(4)  =  76.80\n                                                        Prob > chi2   = 0.0000\nLog likelihood = -183.9706                              Pseudo R2     = 0.6105\n\n-------------------------------------------------------------------------------\n        CRIME | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]\n--------------+----------------------------------------------------------------\nCRIME         |\n          INC |   -1.09739   .3542451    -3.10   0.002    -1.791698   -.4030821\n        HOVAL |  -.2943898   .0963324    -3.06   0.002    -.4831978   -.1055817\n        _cons |   74.55343   6.363788    11.72   0.000     62.08063    87.02622\n--------------+----------------------------------------------------------------\nWqueenS_fr~15 |\n          INC |  -1.398746    .530778    -2.64   0.008    -2.439051   -.3584399\n        HOVAL |    .214841   .1970276     1.09   0.276     -.171326    .6010079\n--------------+----------------------------------------------------------------\n  var(e.CRIME)|   106.8181    21.5805                      71.89125    158.7133\n-------------------------------------------------------------------------------\nWald test of spatial terms:          chi2(2) = 7.31       Prob > chi2 = 0.0259\n\n\n\nAkaike's information criterion and Bayesian information criterion\n\n-----------------------------------------------------------------------------\n       Model |          N   ll(null)  ll(model)      df        AIC        BIC\n-------------+---------------------------------------------------------------\n         SLX |         49          .  -183.9706       6   379.9412   391.2921\n-----------------------------------------------------------------------------\nNote: BIC uses N = number of observations. See [R] BIC note.\n\n\n\n\nprogress   : 50% 100% \n\nAverage impacts                                 Number of obs     =         49\n\n------------------------------------------------------------------------------\n             |            Delta-Method\n             |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]\n-------------+----------------------------------------------------------------\ndirect       |\n         INC |   -1.09739   .3542451    -3.10   0.002    -1.791698   -.4030821\n       HOVAL |  -.2943898   .0963324    -3.06   0.002    -.4831978   -.1055817\n-------------+----------------------------------------------------------------\nindirect     |\n         INC |  -1.398746    .530778    -2.64   0.008    -2.439051   -.3584399\n       HOVAL |    .214841   .1970276     1.09   0.276     -.171326    .6010079\n-------------+----------------------------------------------------------------\ntotal        |\n         INC |  -2.496136   .4671431    -5.34   0.000    -3.411719   -1.580552\n       HOVAL |  -.0795488   .1966064    -0.40   0.686    -.4648903    .3057926\n------------------------------------------------------------------------------\n"
    }
   ]
  },
  {
   "cell_type": "markdown",
   "source": "## SDM",
   "metadata": {
    "cell_id": "00024-bed1237f-606e-44a1-a1e8-5e252b0e8ec5",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00025-2b96392f-6ff1-4ecb-b6c3-461dec194e04",
    "deepnote_cell_type": "code"
   },
   "source": "spregress CRIME INC HOVAL, ml dvarlag(WqueenS_fromStata15) ivarlag(WqueenS_fromStata15: INC HOVAL)\neststo SDM\n\nestat ic\nmat s=r(S)\nquietly estadd scalar AIC = s[1,5]\n\nestat impact",
   "execution_count": null,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "\n  (49 observations)\n  (49 observations (places) used)\n  (weighting matrix defines 49 places)\n\nPerforming grid search ... finished \n\nOptimizing concentrated log likelihood:\n\nIteration 0:   log likelihood = -181.63946  \nIteration 1:   log likelihood = -181.63926  \nIteration 2:   log likelihood = -181.63925  \n\nOptimizing unconcentrated log likelihood:\n\nIteration 0:   log likelihood = -181.63925  \nIteration 1:   log likelihood = -181.63925  (backed up)\n\nSpatial autoregressive model                            Number of obs =     49\nMaximum likelihood estimates                            Wald chi2(5)  =  93.47\n                                                        Prob > chi2   = 0.0000\nLog likelihood = -181.63925                             Pseudo R2     = 0.6120\n\n-------------------------------------------------------------------------------\n        CRIME | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]\n--------------+----------------------------------------------------------------\nCRIME         |\n          INC |  -.9199061   .3395439    -2.71   0.007      -1.5854   -.2544122\n        HOVAL |  -.2971294   .0900249    -3.30   0.001     -.473575   -.1206838\n        _cons |   44.32001   14.18338     3.12   0.002      16.5211    72.11892\n--------------+----------------------------------------------------------------\nWqueenS_fr~15 |\n          INC |  -.5839133   .6053402    -0.96   0.335    -1.770358    .6025317\n        HOVAL |   .2576843   .1850135     1.39   0.164    -.1049356    .6203042\n        CRIME |   .4034626   .1718368     2.35   0.019     .0666687    .7402564\n--------------+----------------------------------------------------------------\n  var(e.CRIME)|   93.27224   19.17105                      62.34442    139.5427\n-------------------------------------------------------------------------------\nWald test of spatial terms:          chi2(3) = 13.88      Prob > chi2 = 0.0031\n\n\n\nAkaike's information criterion and Bayesian information criterion\n\n-----------------------------------------------------------------------------\n       Model |          N   ll(null)  ll(model)      df        AIC        BIC\n-------------+---------------------------------------------------------------\n         SDM |         49          .  -181.6393       7   377.2785   390.5213\n-----------------------------------------------------------------------------\nNote: BIC uses N = number of observations. See [R] BIC note.\n\n\n\n\nprogress   : 50% 100% \n\nAverage impacts                                 Number of obs     =         49\n\n------------------------------------------------------------------------------\n             |            Delta-Method\n             |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]\n-------------+----------------------------------------------------------------\ndirect       |\n         INC |  -1.024988   .3241534    -3.16   0.002    -1.660317   -.3896588\n       HOVAL |  -.2819673   .0911938    -3.09   0.002    -.4607038   -.1032309\n-------------+----------------------------------------------------------------\nindirect     |\n         INC |  -1.495926   .6979787    -2.14   0.032    -2.863939   -.1279129\n       HOVAL |    .215844   .2797595     0.77   0.440    -.3324746    .7641626\n-------------+----------------------------------------------------------------\ntotal        |\n         INC |  -2.520914   .7319696    -3.44   0.001    -3.955548    -1.08628\n       HOVAL |  -.0661233    .308123    -0.21   0.830    -.6700333    .5377866\n------------------------------------------------------------------------------\n"
    }
   ]
  },
  {
   "cell_type": "markdown",
   "source": "### Wald tests",
   "metadata": {
    "cell_id": "00026-b52bfe0c-6d01-4eb6-96b8-90d4e92a1263",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "markdown",
   "source": "### Reduce to OLS?",
   "metadata": {
    "cell_id": "00027-6025fbc0-909d-4c6a-8d18-c74851291140",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00028-0c00f176-2785-4051-9a4e-b3a580d8bba2",
    "deepnote_cell_type": "code"
   },
   "source": "spregress CRIME INC HOVAL, ml dvarlag(WqueenS_fromStata15) ivarlag(WqueenS_fromStata15: INC HOVAL)\n* Wald test: Reduce to OLS? (NO if p < 0.05 of the spatial terms)",
   "execution_count": null,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "  (49 observations)\n  (49 observations (places) used)\n  (weighting matrix defines 49 places)\n\nPerforming grid search ... finished \n\nOptimizing concentrated log likelihood:\n\nIteration 0:   log likelihood = -181.63946  \nIteration 1:   log likelihood = -181.63926  \nIteration 2:   log likelihood = -181.63925  \n\nOptimizing unconcentrated log likelihood:\n\nIteration 0:   log likelihood = -181.63925  \nIteration 1:   log likelihood = -181.63925  (backed up)\n\nSpatial autoregressive model                            Number of obs =     49\nMaximum likelihood estimates                            Wald chi2(5)  =  93.47\n                                                        Prob > chi2   = 0.0000\nLog likelihood = -181.63925                             Pseudo R2     = 0.6120\n\n-------------------------------------------------------------------------------\n        CRIME | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]\n--------------+----------------------------------------------------------------\nCRIME         |\n          INC |  -.9199061   .3395439    -2.71   0.007      -1.5854   -.2544122\n        HOVAL |  -.2971294   .0900249    -3.30   0.001     -.473575   -.1206838\n        _cons |   44.32001   14.18338     3.12   0.002      16.5211    72.11892\n--------------+----------------------------------------------------------------\nWqueenS_fr~15 |\n          INC |  -.5839133   .6053402    -0.96   0.335    -1.770358    .6025317\n        HOVAL |   .2576843   .1850135     1.39   0.164    -.1049356    .6203042\n        CRIME |   .4034626   .1718368     2.35   0.019     .0666687    .7402564\n--------------+----------------------------------------------------------------\n  var(e.CRIME)|   93.27224   19.17105                      62.34442    139.5427\n-------------------------------------------------------------------------------\nWald test of spatial terms:          chi2(3) = 13.88      Prob > chi2 = 0.0031\n"
    }
   ]
  },
  {
   "cell_type": "markdown",
   "source": "### Reduce to SLX?",
   "metadata": {
    "cell_id": "00029-d021e0f4-dbd2-42c3-ae7a-98cce3002d7c",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00030-e37f53a2-f5b5-4458-b74a-658fdd0609ab",
    "deepnote_cell_type": "code"
   },
   "source": "* Wald test: Reduce to SLX? (NO if p < 0.05)\ntest ([WqueenS_fromStata15]CRIME = 0)",
   "execution_count": null,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "\n ( 1)  [WqueenS_fromStata15]CRIME = 0\n\n           chi2(  1) =    5.51\n         Prob > chi2 =    0.0189\n"
    }
   ]
  },
  {
   "cell_type": "markdown",
   "source": "### Reduce to SAR?",
   "metadata": {
    "cell_id": "00031-1c8389f0-b65f-489e-9c2e-2e44df6fc984",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00032-c93e54b4-a839-4fb8-b2fc-b42ccfbbbfe6",
    "deepnote_cell_type": "code"
   },
   "source": "* Wald test: Reduce to SAR? (NO if p < 0.05)\ntest ([WqueenS_fromStata15]INC = 0) ([WqueenS_fromStata15]HOVAL = 0)",
   "execution_count": null,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "\n ( 1)  [WqueenS_fromStata15]INC = 0\n ( 2)  [WqueenS_fromStata15]HOVAL = 0\n\n           chi2(  2) =    2.10\n         Prob > chi2 =    0.3494\n"
    }
   ]
  },
  {
   "cell_type": "markdown",
   "source": "### Reduce to SEM?",
   "metadata": {
    "cell_id": "00033-4700dc5f-1b61-48e6-9356-01af90338604",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00034-167a0851-fa3b-49ff-992a-f03ab158ac81",
    "deepnote_cell_type": "code"
   },
   "source": "* Wald test: Reduce to SEM? (NO if p < 0.05)\ntestnl ([WqueenS_fromStata15]INC = -[WqueenS_fromStata15]CRIME*[CRIME]INC) ([WqueenS_fromStata15]HOVAL = -[WqueenS_fromStata15]CRIME*[CRIME]HOVAL)",
   "execution_count": null,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "\n  (1)  [WqueenS_fromStata15]INC = -[WqueenS_fromStata15]CRIME*[CRIME]INC\n  (2)  [WqueenS_fromStata15]HOVAL = -[WqueenS_fromStata15]CRIME*[CRIME]HOVAL\n\n               chi2(2) =        4.08\n           Prob > chi2 =        0.1300\n"
    }
   ]
  },
  {
   "cell_type": "markdown",
   "source": "## SDEM",
   "metadata": {
    "cell_id": "00035-0bf76f83-b716-4177-a0e3-34758744af4b",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00036-07cf7655-bc62-47ed-b43c-24418815d903",
    "deepnote_cell_type": "code"
   },
   "source": "spregress CRIME INC HOVAL, ml ivarlag(WqueenS_fromStata15: INC HOVAL) errorlag(WqueenS_fromStata15)\neststo SDEM\n\nestat ic\nmat s=r(S)\nquietly estadd scalar AIC = s[1,5]\n\nestat impact",
   "execution_count": null,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "\n  (49 observations)\n  (49 observations (places) used)\n  (weighting matrix defines 49 places)\n\nPerforming grid search ... finished \n\nOptimizing concentrated log likelihood:\n\nIteration 0:   log likelihood =  -181.7792  \nIteration 1:   log likelihood =   -181.779  \nIteration 2:   log likelihood =   -181.779  \n\nOptimizing unconcentrated log likelihood:\n\nIteration 0:   log likelihood =   -181.779  \nIteration 1:   log likelihood =   -181.779  (backed up)\n\nSpatial autoregressive model                            Number of obs =     49\nMaximum likelihood estimates                            Wald chi2(4)  =  46.68\n                                                        Prob > chi2   = 0.0000\nLog likelihood = -181.779                               Pseudo R2     = 0.6092\n\n-------------------------------------------------------------------------------\n        CRIME | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]\n--------------+----------------------------------------------------------------\nCRIME         |\n          INC |  -1.052259   .3233005    -3.25   0.001    -1.685916   -.4186011\n        HOVAL |  -.2781741    .091165    -3.05   0.002    -.4568542    -.099494\n        _cons |   73.64508   8.761175     8.41   0.000      56.4735    90.81667\n--------------+----------------------------------------------------------------\nWqueenS_fr~15 |\n          INC |  -1.204876   .5860084    -2.06   0.040    -2.353431   -.0563208\n        HOVAL |   .1312451   .2111476     0.62   0.534    -.2825966    .5450868\n      e.CRIME |   .4035821   .1773581     2.28   0.023     .0559666    .7511976\n--------------+----------------------------------------------------------------\n  var(e.CRIME)|    93.8033   19.30177                      62.67113    140.4005\n-------------------------------------------------------------------------------\nWald test of spatial terms:          chi2(3) = 12.03      Prob > chi2 = 0.0073\n\n\n\nAkaike's information criterion and Bayesian information criterion\n\n-----------------------------------------------------------------------------\n       Model |          N   ll(null)  ll(model)      df        AIC        BIC\n-------------+---------------------------------------------------------------\n        SDEM |         49          .   -181.779       7    377.558   390.8007\n-----------------------------------------------------------------------------\nNote: BIC uses N = number of observations. See [R] BIC note.\n\n\n\n\nprogress   : 50% 100% \n\nAverage impacts                                 Number of obs     =         49\n\n------------------------------------------------------------------------------\n             |            Delta-Method\n             |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]\n-------------+----------------------------------------------------------------\ndirect       |\n         INC |  -1.052259   .3233005    -3.25   0.001    -1.685916   -.4186011\n       HOVAL |  -.2781741    .091165    -3.05   0.002    -.4568542    -.099494\n-------------+----------------------------------------------------------------\nindirect     |\n         INC |  -1.204876   .5860084    -2.06   0.040    -2.353431   -.0563208\n       HOVAL |   .1312451   .2111476     0.62   0.534    -.2825966    .5450868\n-------------+----------------------------------------------------------------\ntotal        |\n         INC |  -2.257135   .6515178    -3.46   0.001    -3.534086   -.9801833\n       HOVAL |   -.146929   .2403654    -0.61   0.541    -.6180365    .3241785\n------------------------------------------------------------------------------\n"
    }
   ]
  },
  {
   "cell_type": "markdown",
   "source": "## SAC",
   "metadata": {
    "cell_id": "00037-a3913b1a-1618-417d-a170-87283f44f8fb",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00038-c4dc15e5-85d5-42a2-86e7-5ca606eed1f4",
    "deepnote_cell_type": "code"
   },
   "source": "spregress CRIME INC HOVAL, ml dvarlag(WqueenS_fromStata15) errorlag(WqueenS_fromStata15)\neststo SAC\n\nestat ic\nmat s=r(S)\nquietly estadd scalar AIC = s[1,5]\n\nestat impact",
   "execution_count": null,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "\n  (49 observations)\n  (49 observations (places) used)\n  (weighting matrix defines 49 places)\n\nPerforming grid search ... finished \n\nOptimizing concentrated log likelihood:\n\nIteration 0:   log likelihood = -182.57166  \nIteration 1:   log likelihood = -182.55505  \nIteration 2:   log likelihood = -182.55502  \nIteration 3:   log likelihood = -182.55502  \n\nOptimizing unconcentrated log likelihood:\n\nIteration 0:   log likelihood = -182.55502  \nIteration 1:   log likelihood = -182.55502  (backed up)\n\nSpatial autoregressive model                            Number of obs =     49\nMaximum likelihood estimates                            Wald chi2(3)  =  57.82\n                                                        Prob > chi2   = 0.0000\nLog likelihood = -182.55502                             Pseudo R2     = 0.5793\n\n-------------------------------------------------------------------------------\n        CRIME | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]\n--------------+----------------------------------------------------------------\nCRIME         |\n          INC |  -1.042749   .3357121    -3.11   0.002    -1.700733   -.3847656\n        HOVAL |  -.2798409     .09405    -2.98   0.003    -.4641755   -.0955063\n        _cons |   47.91536   9.298756     5.15   0.000     29.69013    66.14058\n--------------+----------------------------------------------------------------\nWqueenS_fr~15 |\n        CRIME |   .3693743   .1792524     2.06   0.039     .0180459    .7207026\n      e.CRIME |   .1464169   .2997182     0.49   0.625      -.44102    .7338538\n--------------+----------------------------------------------------------------\n  var(e.CRIME)|   97.04344   19.77021                      65.09608    144.6697\n-------------------------------------------------------------------------------\nWald test of spatial terms:          chi2(2) = 10.63      Prob > chi2 = 0.0049\n\n\n\nAkaike's information criterion and Bayesian information criterion\n\n-----------------------------------------------------------------------------\n       Model |          N   ll(null)  ll(model)      df        AIC        BIC\n-------------+---------------------------------------------------------------\n         SAC |         49          .   -182.555       6     377.11    388.461\n-----------------------------------------------------------------------------\nNote: BIC uses N = number of observations. See [R] BIC note.\n\n\n\n\nprogress   : 50% 100% \n\nAverage impacts                                 Number of obs     =         49\n\n------------------------------------------------------------------------------\n             |            Delta-Method\n             |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]\n-------------+----------------------------------------------------------------\ndirect       |\n         INC |  -1.080454   .3399105    -3.18   0.001    -1.746666   -.4142414\n       HOVAL |  -.2899596   .0958282    -3.03   0.002    -.4777794   -.1021397\n-------------+----------------------------------------------------------------\nindirect     |\n         INC |  -.5730615   .4220918    -1.36   0.175    -1.400346    .2542232\n       HOVAL |  -.1537916   .1161114    -1.32   0.185    -.3813657    .0737826\n-------------+----------------------------------------------------------------\ntotal        |\n         INC |  -1.653515   .6169502    -2.68   0.007    -2.862715   -.4443151\n       HOVAL |  -.4437511   .1749537    -2.54   0.011    -.7866542   -.1008481\n------------------------------------------------------------------------------\n"
    }
   ]
  },
  {
   "cell_type": "markdown",
   "source": "## GNS",
   "metadata": {
    "cell_id": "00039-2969a80f-3018-41b9-8984-4c59e8cdea88",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00040-f262c14f-a806-4914-a177-e44c50f09e55",
    "deepnote_cell_type": "code"
   },
   "source": "spregress CRIME INC HOVAL, ml dvarlag(WqueenS_fromStata15) ivarlag(WqueenS_fromStata15: INC HOVAL) errorlag(WqueenS_fromStata15)\neststo GNS\n\nestat ic\nmat s=r(S)\nquietly estadd scalar AIC = s[1,5]\n\nestat impact",
   "execution_count": null,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "\n  (49 observations)\n  (49 observations (places) used)\n  (weighting matrix defines 49 places)\n\nPerforming grid search ... finished \n\nOptimizing concentrated log likelihood:\n\nIteration 0:   log likelihood = -181.60541  \nIteration 1:   log likelihood = -181.58046  \nIteration 2:   log likelihood = -181.58014  \nIteration 3:   log likelihood = -181.58014  \n\nOptimizing unconcentrated log likelihood:\n\nIteration 0:   log likelihood = -181.58014  \nIteration 1:   log likelihood = -181.58014  (backed up)\n\nSpatial autoregressive model                            Number of obs =     49\nMaximum likelihood estimates                            Wald chi2(5)  =  62.57\n                                                        Prob > chi2   = 0.0000\nLog likelihood = -181.58014                             Pseudo R2     = 0.6115\n\n-------------------------------------------------------------------------------\n        CRIME | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]\n--------------+----------------------------------------------------------------\nCRIME         |\n          INC |  -.9587964   .3565186    -2.69   0.007     -1.65756   -.2600328\n        HOVAL |  -.2890341   .0924525    -3.13   0.002    -.4702378   -.1078305\n        _cons |   53.04797    31.4573     1.69   0.092    -8.607201    114.7031\n--------------+----------------------------------------------------------------\nWqueenS_fr~15 |\n          INC |  -.7734089   .8571065    -0.90   0.367    -2.453307     .906489\n        HOVAL |   .2184638   .2304209     0.95   0.343    -.2331529    .6700806\n        CRIME |    .284377   .4183839     0.68   0.497    -.5356404    1.104394\n      e.CRIME |   .1632527   .4661928     0.35   0.726    -.7504684    1.076974\n--------------+----------------------------------------------------------------\n  var(e.CRIME)|   94.48532   19.32815                      63.27621    141.0874\n-------------------------------------------------------------------------------\nWald test of spatial terms:          chi2(4) = 12.51      Prob > chi2 = 0.0139\n\n\n\nAkaike's information criterion and Bayesian information criterion\n\n-----------------------------------------------------------------------------\n       Model |          N   ll(null)  ll(model)      df        AIC        BIC\n-------------+---------------------------------------------------------------\n         GNS |         49          .  -181.5801       8   379.1603   394.2948\n-----------------------------------------------------------------------------\nNote: BIC uses N = number of observations. See [R] BIC note.\n\n\n\n\nprogress   : 50% 100% \n\nAverage impacts                                 Number of obs     =         49\n\n------------------------------------------------------------------------------\n             |            Delta-Method\n             |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]\n-------------+----------------------------------------------------------------\ndirect       |\n         INC |  -1.032865   .3233102    -3.19   0.001    -1.666541   -.3991884\n       HOVAL |  -.2793854    .091442    -3.06   0.002    -.4586084   -.1001624\n-------------+----------------------------------------------------------------\nindirect     |\n         INC |  -1.387691   .7255571    -1.91   0.056    -2.809757    .0343749\n       HOVAL |   .1807716   .2720029     0.66   0.506    -.3523444    .7138875\n-------------+----------------------------------------------------------------\ntotal        |\n         INC |  -2.420556   .7598804    -3.19   0.001    -3.909894   -.9312175\n       HOVAL |  -.0986138   .2989642    -0.33   0.742    -.6845729    .4873452\n------------------------------------------------------------------------------\n"
    }
   ]
  },
  {
   "cell_type": "markdown",
   "source": "## Comparison",
   "metadata": {
    "cell_id": "00041-528aa81b-9aad-48a0-93b8-614ce24c1b7e",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00042-b800077f-70cd-4da5-b0c2-b146961842fd",
    "deepnote_cell_type": "code"
   },
   "source": "%html\nesttab OLS SAR SEM SLX SDM SDEM SAC GNS, label stats(AIC) mtitle(\"OLS\" \"SAR\" \"SEM\" \"SLX\" \"SDM\" \"SDEM\" \"SAC\" \"GNS\") html",
   "execution_count": null,
   "outputs": [
    {
     "data": {
      "text/html": "\n<table border=\"0\" width=\"*\">\n<tr><td colspan=9><hr></td></tr>\n<tr><td>                    </td><td>         (1)              </td><td>         (2)              </td><td>         (3)              </td><td>         (4)              </td><td>         (5)              </td><td>         (6)              </td><td>         (7)              </td><td>         (8)              </td></tr>\n<tr><td>                    </td><td>         OLS              </td><td>         SAR              </td><td>         SEM              </td><td>         SLX              </td><td>         SDM              </td><td>        SDEM              </td><td>         SAC              </td><td>         GNS              </td></tr>\n<tr><td colspan=9><hr></td></tr>\n<tr><td>main                </td><td>                          </td><td>                          </td><td>                          </td><td>                          </td><td>                          </td><td>                          </td><td>                          </td><td>                          </td></tr>\n<tr><td>Income              </td><td>      -1.597<sup>***</sup></td><td>      -1.049<sup>**</sup> </td><td>      -0.957<sup>*</sup>  </td><td>      -1.097<sup>**</sup> </td><td>      -0.920<sup>**</sup> </td><td>      -1.052<sup>**</sup> </td><td>      -1.043<sup>**</sup> </td><td>      -0.959<sup>**</sup> </td></tr>\n<tr><td>                    </td><td>     (-4.78)              </td><td>     (-3.17)              </td><td>     (-2.54)              </td><td>     (-3.10)              </td><td>     (-2.71)              </td><td>     (-3.25)              </td><td>     (-3.11)              </td><td>     (-2.69)              </td></tr>\n<tr><td colspan=9>&nbsp;</td></tr>\n<tr><td>House value         </td><td>      -0.274<sup>*</sup>  </td><td>      -0.266<sup>**</sup> </td><td>      -0.305<sup>***</sup></td><td>      -0.294<sup>**</sup> </td><td>      -0.297<sup>***</sup></td><td>      -0.278<sup>**</sup> </td><td>      -0.280<sup>**</sup> </td><td>      -0.289<sup>**</sup> </td></tr>\n<tr><td>                    </td><td>     (-2.65)              </td><td>     (-3.00)              </td><td>     (-3.30)              </td><td>     (-3.06)              </td><td>     (-3.30)              </td><td>     (-3.05)              </td><td>     (-2.98)              </td><td>     (-3.13)              </td></tr>\n<tr><td colspan=9>&nbsp;</td></tr>\n<tr><td>Constant            </td><td>       68.62<sup>***</sup></td><td>       45.60<sup>***</sup></td><td>       60.28<sup>***</sup></td><td>       74.55<sup>***</sup></td><td>       44.32<sup>**</sup> </td><td>       73.65<sup>***</sup></td><td>       47.92<sup>***</sup></td><td>       53.05              </td></tr>\n<tr><td>                    </td><td>     (14.49)              </td><td>      (5.73)              </td><td>     (10.21)              </td><td>     (11.72)              </td><td>      (3.12)              </td><td>      (8.41)              </td><td>      (5.15)              </td><td>      (1.69)              </td></tr>\n<tr><td colspan=9><hr></td></tr>\n<tr><td>WqueenS_fromStata15 </td><td>                          </td><td>                          </td><td>                          </td><td>                          </td><td>                          </td><td>                          </td><td>                          </td><td>                          </td></tr>\n<tr><td>Crime               </td><td>                          </td><td>       0.423<sup>***</sup></td><td>                          </td><td>                          </td><td>       0.403<sup>*</sup>  </td><td>                          </td><td>       0.369<sup>*</sup>  </td><td>       0.284              </td></tr>\n<tr><td>                    </td><td>                          </td><td>      (3.37)              </td><td>                          </td><td>                          </td><td>      (2.35)              </td><td>                          </td><td>      (2.06)              </td><td>      (0.68)              </td></tr>\n<tr><td colspan=9>&nbsp;</td></tr>\n<tr><td>e.Crime             </td><td>                          </td><td>                          </td><td>       0.547<sup>***</sup></td><td>                          </td><td>                          </td><td>       0.404<sup>*</sup>  </td><td>       0.146              </td><td>       0.163              </td></tr>\n<tr><td>                    </td><td>                          </td><td>                          </td><td>      (3.47)              </td><td>                          </td><td>                          </td><td>      (2.28)              </td><td>      (0.49)              </td><td>      (0.35)              </td></tr>\n<tr><td colspan=9>&nbsp;</td></tr>\n<tr><td>Income              </td><td>                          </td><td>                          </td><td>                          </td><td>      -1.399<sup>**</sup> </td><td>      -0.584              </td><td>      -1.205<sup>*</sup>  </td><td>                          </td><td>      -0.773              </td></tr>\n<tr><td>                    </td><td>                          </td><td>                          </td><td>                          </td><td>     (-2.64)              </td><td>     (-0.96)              </td><td>     (-2.06)              </td><td>                          </td><td>     (-0.90)              </td></tr>\n<tr><td colspan=9>&nbsp;</td></tr>\n<tr><td>House value         </td><td>                          </td><td>                          </td><td>                          </td><td>       0.215              </td><td>       0.258              </td><td>       0.131              </td><td>                          </td><td>       0.218              </td></tr>\n<tr><td>                    </td><td>                          </td><td>                          </td><td>                          </td><td>      (1.09)              </td><td>      (1.39)              </td><td>      (0.62)              </td><td>                          </td><td>      (0.95)              </td></tr>\n<tr><td colspan=9><hr></td></tr>\n<tr><td>/                   </td><td>                          </td><td>                          </td><td>                          </td><td>                          </td><td>                          </td><td>                          </td><td>                          </td><td>                          </td></tr>\n<tr><td>var(e.CRIME)        </td><td>                          </td><td>       96.86<sup>***</sup></td><td>       97.67<sup>***</sup></td><td>       106.8<sup>***</sup></td><td>       93.27<sup>***</sup></td><td>       93.80<sup>***</sup></td><td>       97.04<sup>***</sup></td><td>       94.49<sup>***</sup></td></tr>\n<tr><td>                    </td><td>                          </td><td>      (4.90)              </td><td>      (4.78)              </td><td>      (4.95)              </td><td>      (4.87)              </td><td>      (4.86)              </td><td>      (4.91)              </td><td>      (4.89)              </td></tr>\n<tr><td colspan=9><hr></td></tr>\n<tr><td>AIC                 </td><td>       380.8              </td><td>       375.3              </td><td>       377.5              </td><td>       379.9              </td><td>       377.3              </td><td>       377.6              </td><td>       377.1              </td><td>       379.2              </td></tr>\n<tr><td colspan=9><hr></td></tr>\n<tr><td colspan=9>\n<i>t</i> statistics in parentheses\n<br /><sup>*</sup> <i>p</i> < 0.05, <sup>**</sup> <i>p</i> < 0.01, <sup>***</sup> <i>p</i> < 0.001\n</td></tr>\n</table>\n\n",
      "text/plain": "This front-end or document format cannot display HTML"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00043-62d77d5c-0baa-4c5d-801f-51dd7714e1dd",
    "deepnote_cell_type": "code"
   },
   "source": "eststo clear",
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": "The following comparison requires Stata 17.  Caution is needed as the p-values are not shown",
   "metadata": {
    "cell_id": "00044-1f872631-cc74-41fc-aae8-32e6c1740d21",
    "deepnote_cell_type": "markdown"
   }
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00045-8b58dcfd-7c69-449c-8c39-63cc5fb2c870",
    "deepnote_cell_type": "code"
   },
   "source": "collect clear\n\nquietly spregress CRIME INC HOVAL, ml dvarlag(WqueenS_fromStata15)\ncollect: quietly estat impact\n\nquietly spregress CRIME INC HOVAL, ml ivarlag(WqueenS_fromStata15: INC HOVAL)\ncollect: quietly estat impact\n\nquietly spregress CRIME INC HOVAL, ml dvarlag(WqueenS_fromStata15) ivarlag(WqueenS_fromStata15: INC HOVAL)\ncollect: quietly estat impact\n\nquietly spregress CRIME INC HOVAL, ml ivarlag(WqueenS_fromStata15: INC HOVAL) errorlag(WqueenS_fromStata15)\ncollect: quietly estat impact\n\nquietly spregress CRIME INC HOVAL, ml dvarlag(WqueenS_fromStata15) errorlag(WqueenS_fromStata15)\ncollect: quietly estat impact\n\nquietly spregress CRIME INC HOVAL, ml dvarlag(WqueenS_fromStata15) ivarlag(WqueenS_fromStata15: INC HOVAL) errorlag(WqueenS_fromStata15)\ncollect: quietly estat impact\n\n\ncollect label list cmdset, all\ncollect style autolevels result b_direct b_indirect  \ncollect label levels cmdset 1 \"SAR\" 2 \"SLX\" 3 \"SDM\" 4 \"SDEM\" 5 \"SAC\" 6 \"GNS\"\ncollect style cell, nformat(%7.2f)\ncollect layout (colname#result) (cmdset) \n",
   "execution_count": null,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n  Collection: default\n   Dimension: cmdset\n       Label: Command results index\nLevel labels:\n           1  \n           2  \n           3  \n           4  \n           5  \n           6  \n\n\n\n\n\nCollection: default\n      Rows: colname#result\n   Columns: cmdset\n   Table 1: 6 x 6\n\n--------------------------------------------------\n             |   SAR   SLX   SDM  SDEM   SAC   GNS\n-------------+------------------------------------\nIncome       |                                    \n  b_direct   | -1.10 -1.10 -1.02 -1.05 -1.08 -1.03\n  b_indirect | -0.72 -1.40 -1.50 -1.20 -0.57 -1.39\nHouse value  |                                    \n  b_direct   | -0.28 -0.29 -0.28 -0.28 -0.29 -0.28\n  b_indirect | -0.18  0.21  0.22  0.13 -0.15  0.18\n--------------------------------------------------\n"
    }
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "cell_id": "00046-9349e320-329b-4e09-878f-bfe7d633819d",
    "deepnote_cell_type": "code"
   },
   "source": "",
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": "<a style='text-decoration:none;line-height:16px;display:flex;color:#5B5B62;padding:10px;justify-content:end;' href='https://deepnote.com?utm_source=created-in-deepnote-cell&projectId=d3458c2b-7b0a-425f-b3ea-855191342009' target=\"_blank\">\n<img alt='Created in deepnote.com' style='display:inline;max-height:16px;margin:0px;margin-right:7.5px;' src='' > </img>\nCreated in <span style='font-weight:600;margin-left:4px;'>Deepnote</span></a>",
   "metadata": {
    "tags": [],
    "created_in_deepnote_cell": true,
    "deepnote_cell_type": "markdown"
   }
  }
 ],
 "nbformat": 4,
 "nbformat_minor": 5,
 "metadata": {
  "kernelspec": {
   "display_name": "Stata",
   "language": "stata",
   "name": "stata"
  },
  "language_info": {
   "codemirror_mode": "stata",
   "file_extension": ".do",
   "mimetype": "text/x-stata",
   "name": "stata",
   "version": "17"
  },
  "deepnote_notebook_id": "9448027d-19c9-4c2e-a7a4-734d443fd04c",
  "deepnote": {},
  "deepnote_execution_queue": []
 }
}